package day_2023_7_to_10;

/**
 * @author haomin
 * @date 2023/08/02 00:05
 **/
public class Day_8_2 {
    class Solution {
        public boolean isSubStructure(TreeNode A, TreeNode B) {
            if (A == null || B == null) return false;
            return isSubStructureHlper(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
        }
        public boolean isSubStructureHlper(TreeNode a, TreeNode b) {
            if (b == null) return true;
            if (a == null) return false;
            return a.val == b.val && isSubStructureHlper(a.left, b.left) && isSubStructureHlper(a.right, b.right);
        }
    }

}